package com.example.gpstest;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

public class DrawTextActivity extends Activity implements OnTouchListener {
	static int i = 0;
	float x = 200;
	float y = 200;
	float x1 = 0;
	float y1 = 0;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.create_message);
		ViewGroup layMain = (ViewGroup) this.findViewById(R.id.createMessagePanel);
		layMain.setOnTouchListener((OnTouchListener) this);
		View drawV=new DrawObjView(this);
		layMain.addView(drawV);
		View textV=new TextObjView(this);
		layMain.addView(textV);

	}

	public boolean onTouch(View v, MotionEvent event) {

		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN: {
			x = event.getX();
			y = event.getY();
		}
		}
		return false;
	}

	public class DrawObjView extends View {

		public DrawObjView(Context context) {
			super(context);
		}

		protected void onDraw(Canvas canvas) {
			Paint p = new Paint();
			p.setColor(Color.RED);

			canvas.drawLine(15, 15, x+5, y+5, p);
			invalidate();
		}
	}
	
	public class TextObjView extends View {

		public TextObjView(Context context) {
			super(context);
		}

		protected void onDraw(Canvas canvas) {
			Paint p = new Paint();
			p.setColor(Color.GREEN);

			canvas.drawLine(15, 15, x-5, y-5, p);
			canvas.drawText("X:"+x+" Y:"+y, x, y, p);
			//invalidate();
		}

	}

}